<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
           超市库存管理系统
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" id="inlibrary-edit-id">
            	
            		<input type="hidden" name="id" value="${tbInlibrary.id}" />
            	
            	
                <div class="layui-form-item">
                    <label for="L_name" class="layui-form-label">
                        	商品名称
                    </label>
                    <div class="layui-input-inline">
                    	<select name="sid">
                    		<c:forEach items="${tbUserEx.rows}" var="item">
                    			<c:if test="${tbInlibrary.sid == item.id}">
                    				<option value="${item.id}" selected>${item.name}</option>
                    			</c:if>
                    			<c:if test="${tbInlibrary.sid != item.id}">
                    				<option value="${item.id}">${item.name}</option>
                    			</c:if>
                    			
                    		</c:forEach>
                    	</select>
                        
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_type" class="layui-form-label">
                        	商品类别
                    </label>
                    <div class="layui-input-inline">
                    	
                        <input type="text" id="L_type" name="type"  value="${tbInlibrary.type}" required="" lay-verify="a_type"
                        autocomplete="off" class="layui-input" >
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        	商品单价
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="L_price" name="price" value="${tbInlibrary.price}" required="" lay-verify="a_price"
                        autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">缩略图
                    </label>
                    <img id="LAY_demo_upload" width="400"  src="${tbInlibrary.img}" style="width: 100px;">
                    <input type="hidden" id="img_id" name="img" value="${tbInlibrary.img}" required="" lay-verify="a_img"/>
                    
                </div>
                <div class="layui-form-item">
                    <label for="link" class="layui-form-label">
                        	图片上传
                    </label>
                    <div class="layui-input-inline">
                      <div class="site-demo-upbar">
                        <input type="file" name="file" class="layui-upload-file" id="test">
                      </div>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*不支持中文图片文件名</span>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        	入库数量
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="L_inlibrary" name="inlibrary" value="${tbInlibrary.inlibrary}" required="" lay-verify="a_inlibrary"
                        autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_description" class="layui-form-label">
                        	入库原因
                    </label>
                    <div class="layui-input-inline">
                    	
                        <select name="description">
                        	<c:if test="${tbInlibrary.description eq '采购入库'}">
                        			<option value='采购入库' selected>采购入库</option>
                        			<option value='退货入库'>退货入库</option>
                        	</c:if>
                        	<c:if test="${tbInlibrary.description eq '退货入库'}">
                        			<option value='采购入库'>采购入库</option>
                        			<option value='退货入库' selected>退货入库</option>
                        	</c:if>
                        </select>
                    </div>
                    
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        	入库时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="dtimes" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${tbInlibrary.dtime}" />" id="datetime" ay-verify="a_dtime">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        	保存
                    </button>
                </div>
            </form>
        </div>
        <script src="./lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="./js/x-layui.js" charset="utf-8">
        </script>
        
        <script src="./js/jquery-3.3.1.js" charset="utf-8">
        </script>
        
        
        <script>
        
        	
        
        
            layui.use(['laydate','form','layer','upload'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
			var laydate = layui.laydate;
              
              var start = {
                 min: '1970-01-01 00:00:01'
                 ,max: '2099-06-16 23:59:59'
                 ,istoday: false
                 ,choose: function(datas){
                   end.min = datas; //开始日选好后，重置结束日的最小日期
                   end.start = datas //将结束日的初始值设定为开始日
                 }
               };
               
               var end = {
                 min: '1970-01-01 00:00:01'
                 ,max: '2099-06-16 23:59:59'
                 ,istoday: false
                 ,choose: function(datas){
                   start.max = datas; //结束日选好后，重置开始日的最大日期
                 }
               };
               
               document.getElementById('datetime').onclick = function(){
                 start.elem = this;
                 laydate(start);
               }
               document.getElementById('datetime').onclick = function(){
                 end.elem = this
                 laydate(end);
               }
              
              
              
              //自定义验证规则
              form.verify({
                nikename: function(value){
                  if(value.length < 5){
                    return '昵称至少得5个字符啊';
                  }
                }
                ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                ,repass: function(value){
                    if($('#L_pass').val()!=$('#L_repass').val()){
                        return '两次密码不一致';
                    }
                }
                ,a_type: function(value){
                    if(value.length <= 0){
                        return '类别不能为空';
                      }
                }
                ,a_price: function(value){
                    if(value<=0 || value.length <= 0){
                        return '价钱不能为空,且价钱大于0';
                      }
                }
                ,a_img: function(value){
                    if(value.length <= 0){
                        return '请上传图片';
                      }
                }
                ,a_inlibrary: function(value){
                    if(value<=0 || value.length <= 0){
                        return '入库数量不能为空,入库数量大于0';
                      }
                }
                ,a_dtime: function(value){
                    if(value.length <= 0){
                        return '入库时间不能为空';
                      }
                }
              });

              
              
            //图片上传接口
              layui.upload({
                url: '${pageContext.request.contextPath}/storage-uploadimg' //上传接口
                ,success: function(res){ //上传成功后的回调
                    console.log(res.error);
                  $('#LAY_demo_upload').attr('src',res.error);
                  $('#img_id').attr('value',res.error);
                }
              });
              
              
              
              //监听提交
              form.on('submit(add)', function(data){
                console.log(data);
                //发异步，把数据提交给php
               $.post("${pageContext.request.contextPath}/inlibraryedit",$("#inlibrary-edit-id").serialize(),function(data){
                	if(data.code == 200){
                		
                		layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                	}else{
                		layer.alert("修改失败", {icon: 5},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                		
                	}
                });
                
                
                return false;
              }); 
              
              
            });
        </script>
        
    </body>

</html>